package com.bang.daybreak.security.model;

import com.bang.daybreak.user.model.entity.SysUser;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

import java.util.Collection;
import java.util.Set;

/**
 * <p>
 * 封装系统用户实体信息，必须实现UserDetails接口
 * </p>
 *
 * @version 1.0
 * @author : wdj
 * @date : 2019/8/10 0010 下午 15:29
 */
public class SysUserDetails implements UserDetails {
    private static final long serialVersionUID = -1036982132058658668L;

    /**
     * SysUser
     */
    private SysUser sysUser;

    /**
     * 实现UserDetails接口中的属性，存储角色.
     */
    private Set<? extends GrantedAuthority> authorities;


    /**
     * 获取权限信息
     *
     * @return
     */
    @Override
    public Collection<? extends GrantedAuthority> getAuthorities() {
        return authorities;
    }

    @Override
    public String getPassword() {
        return sysUser.getPassword();
    }

    @Override
    public String getUsername() {
        return sysUser.getUsername();
    }

    /**
     * 账号是否过期.
     *
     * @return
     */
    @Override
    public boolean isAccountNonExpired() {
        return true;
    }

    /**
     * 账号是否锁定
     *
     * @return
     */
    @Override
    public boolean isAccountNonLocked() {
        return true;
    }

    /**
     * 密码是否过期。
     *
     * @return
     */
    @Override
    public boolean isCredentialsNonExpired() {
        return true;
    }

    @Override
    public boolean isEnabled() {
        return true;
    }

    public SysUser getSysUser() {
        return sysUser;
    }

    public void setSysUser(SysUser sysUser) {
        this.sysUser = sysUser;
    }

    public void setAuthorities(Set<? extends GrantedAuthority> authorities) {
        this.authorities = authorities;
    }
}
